﻿<Window x:Class="Aeon.Emulator.Launcher.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:emu="clr-namespace:Aeon.Presentation;assembly=Aeon.Presentation"
    xmlns:local="clr-namespace:Aeon.Emulator.Launcher"
    Title="Aeon" Width="800" Height="600" MinWidth="360" MinHeight="270" Icon="Aeon.ico" DataContext="{Binding ElementName=emulatorDisplay}">
    <Window.CommandBindings>
        <CommandBinding Command="Close" CanExecute="Close_CanExecute" Executed="Close_Executed" />
        <CommandBinding Command="Copy" CanExecute="Copy_CanExecute" Executed="Copy_Executed" />
        <CommandBinding Command="{x:Static local:MainWindow.MapDrivesCommand}" CanExecute="MapDrives_CanExecute" Executed="MapDrives_Executed" />
        <CommandBinding Command="{x:Static local:MainWindow.ShowInstructionLogCommand}" CanExecute="ShowInstructionLog_CanExecute" Executed="ShowInstructionLog_Executed" />
    </Window.CommandBindings>
    <Window.Resources>
        <Style x:Key="disableOnRunStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding EmulatorState, ElementName=emulatorDisplay}" Value="Running">
                    <Setter Property="Control.IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <local:MouseModeConverter x:Key="mouseModeConverter" />
        <local:PercentConverter x:Key="percentConverter" />
        <BooleanToVisibilityConverter x:Key="booleanConverter" />
    </Window.Resources>
    <Window.Background>
        <LinearGradientBrush>
            <GradientStop Color="SteelBlue" Offset="0" />
            <GradientStop Color="#FF1D4461" Offset="1" />
        </LinearGradientBrush>
    </Window.Background>
    <DockPanel>
        <Menu Name="mainMenu" DockPanel.Dock="Top">
            <MenuItem Header="_Aeon">
                <MenuItem Header="_New Session..." Click="NewSession_Click" />
                <MenuItem Header="_Quick Launch Program..." Click="QuickLaunch_Click" />
                <MenuItem Header="_Quick Launch Command Prompt..." Click="CommandPrompt_Click" />
                <MenuItem Header="Map _Drives..." Command="{x:Static local:MainWindow.MapDrivesCommand}" />
                <Separator />
                <MenuItem Header="_Pause" Command="{Binding PauseCommand}" />
                <MenuItem Header="R_esume" Command="{Binding ResumeCommand}" />
                <Separator />
                <MenuItem Header="E_xit" Command="Close" />
            </MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Header="_Copy Screen" Command="Copy" />
                <MenuItem Header="_Record" Click="MenuItem_Click" Visibility="Collapsed" />
                <MenuItem Header="_Stop Recording" Click="MenuItem_Click_1" Visibility="Collapsed" />
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Name="viewToolBarMenuItem" Header="_Toolbar" IsCheckable="True" IsChecked="True" />
                <Separator />
                <MenuItem Header="_Lock Aspect Ratio" IsCheckable="True" IsChecked="{Binding IsAspectRatioLocked}" />
                <Separator />
                <MenuItem Header="_Performance Window" Click="PerformanceWindow_Click" />
                <MenuItem Header="_Instruction Log" Command="{x:Static local:MainWindow.ShowInstructionLogCommand}" Visibility="Collapsed" />
            </MenuItem>
            <MenuItem Header="_Debug">
                <MenuItem Name="showDebuggerMenuItem" Header="Debugger" Click="ShowDebugger_Click" Tag="__INTERNAL__" />
                <MenuItem Name="enableLogMenuItem" Header="Enable Instruction _Log" IsCheckable="True" Click="EnableInstructionLog_Click" Tag="__INTERNAL__" />
                <MenuItem Name="colorPaletteMenuItem" Header="Color Palette" Click="ShowPalette_Click" />
                <MenuItem Name="audioBufferMenuItem" Header="Audio Buffer" Click="ShowAudioBuffer_Click" Tag="__INTERNAL__" />
                <MenuItem Name="instructionProfilerMenuItem" Header="Instruction Profiler" Click="instructionProfilerMenuItem_Click" Tag="__INTERNAL__" />
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Header="Check for _Update" Click="CheckForUpdate_Click" />
                <MenuItem Header="aeonemulator.net" Click="Website_Click" />
                <Separator />
                <MenuItem Header="_About Aeon" Click="About_Click" />
            </MenuItem>
        </Menu>
        <ToolBarTray Name="toolBar" DockPanel.Dock="Top" IsLocked="True" Visibility="{Binding IsChecked, ElementName=viewToolBarMenuItem, Converter={StaticResource booleanConverter}}">
            <ToolBarTray.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="WhiteSmoke" Offset="0.0" />
                    <GradientStop Color="DimGray" Offset="1.0" />
                </LinearGradientBrush>
            </ToolBarTray.Background>
            <ToolBarTray.Effect>
                <DropShadowEffect />
            </ToolBarTray.Effect>
            <ToolBar Background="Transparent">
                <ToolBar.Resources>
                    <Style x:Key="commandStyle">
                        <Setter Property="Shape.Stroke" Value="DarkGreen" />
                        <Setter Property="Shape.Fill">
                            <Setter.Value>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Color="LightGreen" Offset="0.0" />
                                    <GradientStop Color="DarkGreen" Offset="1.0" />
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <Trigger Property="Control.IsEnabled" Value="False">
                                <Setter Property="Shape.Stroke" Value="DimGray" />
                                <Setter Property="Shape.Fill">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                            <GradientStop Color="LightGray" Offset="0.0" />
                                            <GradientStop Color="DimGray" Offset="1.0" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="Control.IsEnabled" Value="True">
                                <Setter Property="Shape.BitmapEffect">
                                    <Setter.Value>
                                        <DropShadowBitmapEffect Softness="0" ShadowDepth="2" Opacity="0.25" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToolBar.Resources>
                <ToolBar.Template>
                    <ControlTemplate>
                        <ToolBarPanel IsItemsHost="True" Name="PART_ToolBarPanel" Margin="0,1,2,2" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                    </ControlTemplate>
                </ToolBar.Template>
                <Button ToolTip="Run Program..." Click="QuickLaunch_Click">
                    <Image Width="16" Height="16" Source="Resources/openfolderHS.png" />
                </Button>
                <Separator />
                <Button Command="{Binding ResumeCommand}" ToolTip="Resume">
                    <Canvas Width="16" Height="16">
                        <Polygon Points="0,0 0,9 5,4 0,0" Style="{StaticResource commandStyle}">
                            <Polygon.RenderTransform>
                                <TranslateTransform X="6" Y="4" />
                            </Polygon.RenderTransform>
                        </Polygon>
                    </Canvas>
                </Button>
                <Button Command="{Binding PauseCommand}" ToolTip="Pause" ToolBar.OverflowMode="Never">
                    <Canvas Width="16" Height="16">
                        <Rectangle Width="4" Height="10" Style="{StaticResource commandStyle}">
                        </Rectangle>
                        <Rectangle Width="4" Height="10" Canvas.Left="5" Style="{StaticResource commandStyle}">
                        </Rectangle>
                        <Canvas.RenderTransform>
                            <TranslateTransform X="3" Y="3" />
                        </Canvas.RenderTransform>
                    </Canvas>
                </Button>
                <Separator />
                <ToggleButton Name="mouseIntegrationButton" ToolTip="Toggle Mouse Integration" ToolBar.OverflowMode="Never"
                              IsChecked="{Binding MouseInputMode, Converter={StaticResource mouseModeConverter}}">
                    <Image Width="16" Height="16" Source="Resources/MouseIntegration.png" />
                </ToggleButton>
                <Separator />
                <Label Content="Speed:" />
                <Button Template="{StaticResource roundButtonTemplate}" ToolTip="Slow Down Emulation"
                        Width="18" Height="18" Padding="0" Click="slowerButton_Click">
                    <Button.Style>
                        <Style TargetType="{x:Type Button}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding EmulationSpeed}" Value="2">
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                    <Label FontFamily="Courier New" FontWeight="Bold" Content="-" Padding="0" />
                </Button>
                <TextBlock Width="40" Text="{Binding EmulationSpeed, Converter={StaticResource percentConverter}}"
                           TextAlignment="Center" VerticalAlignment="Center" />
                <Button Template="{StaticResource roundButtonTemplate}" ToolTip="Speed Up Emulation"
                        Width="18" Height="18" Padding="0" Click="fasterButton_Click" >
                    <Button.Style>
                        <Style TargetType="{x:Type Button}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding EmulationSpeed}" Value="20">
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                    <Label FontFamily="Courier New" FontWeight="Bold" Content="+" Padding="0" />
                </Button>
                <Separator />
                <Button Command="{x:Static local:MainWindow.MapDrivesCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Resources/3.5_Disk_Drive.png" Height="20" />
                        <TextBlock Text="Drives" Margin="3,1" />
                    </StackPanel>
                </Button>
            </ToolBar>
        </ToolBarTray>
        <StatusBar DockPanel.Dock="Bottom" Visibility="Collapsed">
            <StatusBar.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="WhiteSmoke" Offset="0.0" />
                    <GradientStop Color="DimGray" Offset="1.0" />
                </LinearGradientBrush>
            </StatusBar.Background>
            <Label Name="statusLabel" Padding="0" />
        </StatusBar>
        <emu:EmulatorDisplay Name="emulatorDisplay" EmulatorStateChanged="emulatorDisplay_EmulatorStateChanged"
                             EmulationError="emulatorDisplay_EmulationError" CurrentProcessChanged="emulatorDisplay_CurrentProcessChanged"
                             Margin="0,7,0,0" />
    </DockPanel>
</Window>
